<?php
namespace app\index\controller;

date_default_timezone_set('PRC'); 
use think\Request;
use think\Controller;
use think\Model;
use think\Cookie;
use think\Session;

class Index extends Controller
{
    public function index(Request $request)
    {
        $brandList = model("Index")->getBrandListIndex();
        $productList = model("Index")->getProductListIndex();
        return view('/index',['brandList'=>$brandList,'productList'=>$productList]);
    }

    public function contact() {
        return view('/contact');
    }

    public function faq() {
        return view('/FAQ');
    }

    public function brand(Request $request) {
        $brandId = $request->get("brandId");
        $q = $request->get("q");
        $page = $request->get("page");
        $brandList = model("Index")->getAllBrand();
        $productList = model("Index")->getAllProduct($brandId,$q,$page);
        return view('/xuanc',['brandList'=>$brandList,'productList'=>$productList]);
    }

    public function introduce() {
        return view('/introduce');
    }

    public function flow() {
        return view('/flow');
    }

    public function product(Request $request) {
        $productId = $request->get("productId");
        $productInfo = model("Index")->getProductInfo($productId);
        return view('/xuanche',['productInfo'=>$productInfo]);
    }

    public function addIntention(Request $request) {
        if ($request->isPost() && $request->isAjax()) {
            $data = array();
            $data['name'] = $request->post("name");
            $data['phone'] = $request->post("phone");
            $data['province'] = $request->post("province");
            $data['city'] = $request->post("city");
            $data['area'] = $request->post("area");
            $data['prodcut_id'] = $request->post("productId");
            $data['product_info'] = $request->post("pinfo");
            $data['add_time'] = date('y-m-d h:i:s',time());
            $resp = model("Index")->setIntention($data);
            if ($resp) {
                $this->success("购车意向提交成功,稍后客服会和您联系！");
            } else {
                $this->error("购车意向提交失败,请联系0571-28098514！");
            }
        }
    }
}
